#include "SanPham.h"

CSanPham::CSanPham(void)
{
}
CSanPham::CSanPham(LPDIRECT3DTEXTURE9 img, LPDIRECT3DDEVICE9 dev, int num, int x, int y, int w, int h, int speed)
{
	this->img = img;
	this->result = D3DXCreateSprite(dev, &(this->handler));
	this->dev = dev;
	this->num = num;
	this->x = x;
	this->y = y;
	this->w = w;
	this->h = h;
	this->speed = speed;
	this->sprite.x = x;
	this->sprite.y = y;
	this->sprite.width = w;
	this->sprite.height = h;
	this->sprite.movey = speed;
}
void CSanPham::setSpeed(int val){
	this->sprite.movey = val;
}
void CSanPham::draw() 
{
	handler->Begin(D3DXSPRITE_ALPHABLEND);
	//create vector to update sprite position
	D3DXVECTOR3 position((float)this->sprite.x, (float)this->sprite.y, 0);
	//draw the sprite
	handler->Draw(
		this->img, 
		NULL,
		NULL,
		&position,
		D3DCOLOR_XRGB(255,255,255));
	//stop drawing
	handler->End();

}
void CSanPham::update()
{
	this->sprite.y += this->sprite.movey;
}
bool CSanPham::checkLifeTime() {
	if (this->sprite.y >= 480 - this->sprite.height){
		return true;
	}return false;
}
bool CSanPham::checkCollision(CRo* ro) {
	int x = ro->getSprite().x;
	int y = ro->getSprite().y;
	if (this->sprite.x >= ro->getSprite().x && 
		this->sprite.x <= ro->getSprite().x + ro->getSprite().width &&
		this->sprite.y >= ro->getSprite().y &&
		this->sprite.y <= ro->getSprite().y + this->sprite.height) 
	{
		return true;
	}
	return false;
}
int CSanPham::getType(){
	return num;
}
SPRITE CSanPham::getProduct() {
	return this->sprite;
}
CSanPham::~CSanPham(void)
{
	img->Release();
	handler->Release();
}


